~ chicken-core (master) /manual/Extensions to the standard


  1[[tags: manual]]
  2
  3[[toc:]]
  4
  5== Extensions to the R7RS standard
  6
  7=== Brackets and braces
  8
  9The brackets {{[ ... ]}} and the braces {{ { ... } }} are
 10provided as an alternative syntax for {{( ... )}}.  A number of reader
 11extensions is provided.
 12
 13=== User defined character names
 14
 15User defined character names are supported. See
 16{{char-name}}. Numeric hexadecimal character codes above are supported and can be read
 17using ''#\uXXXX'' and ''#\UXXXXXXXX'', in addition to the standard ''\x...;'' notation.
 18
 19Non-standard characters names supported are {{#\linefeed}}, {{#\vtab}}, {{#\nul}}, {{#\page}} and {{#\esc}}.
 20
 21== Non-standard read syntax
 22
 23=== Multiline Block Comment
 24
 25<read>#|</read>
 26
 27 #| ... |#
 28
 29A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].
 30
 31=== Expression Comment
 32
 33<read>#;</read>
 34
 35 #;EXPRESSION
 36
 37Treats {{EXPRESSION}} as a comment.  That is, the comment runs through the whole S-expression, regardless of newlines, which saves you from having to comment out every line, or add a newline in the middle of your parens to make the commenting of the last line work, or other things like that. Implements [[http://srfi.schemers.org/srfi-62/srfi-62.html|SRFI-62]].
 38
 39=== External Representation
 40
 41<read>#,</read>
 42
 43 #,(CONSTRUCTORNAME DATUM ...)
 44
 45Allows user-defined extension of external representations. (For more information see the documentation for
 46[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])
 47
 48=== Location Expression
 49
 50<read> #$EXPRESSION</read>
 51
 52An abbreviation for {{(location EXPRESSION)}}.
 53
 54=== Bytevector strings
 55
 56<read>#u8"..."</read>
 57
 58String syntax for bytevectors, as an alternative to {{#u8(...)}}. The usual escape sequences for strings are recognized.
 59
 60=== Keyword
 61
 62<read>#:</read>
 63
 64 #:SYMBOL
 65 SYMBOL:
 66 :SYMBOL
 67
 68Syntax for keywords. Keywords are symbol-like objects that evaluate to themselves, and as such don't have to be quoted.  Either {{SYMBOL:}} or {{:SYMBOL}} is accepted, depending on the setting of the {{keyword-style}} parameter, but never both.  {{#:SYMBOL}} is always accepted.
 69
 70=== Multiline String Constant
 71
 72<read>#<<</read>
 73
 74 #<<TAG
 75
 76Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:
 77
 78 (define msg #<<END
 79  "Hello, world!", she said.
 80 END
 81 )
 82
 83is equivalent to
 84
 85 (define msg "\"Hello, world!\", she said.")
 86
 87=== Multiline String Constant with Embedded Expressions
 88
 89<read>#<#</read>
 90
 91 #<#TAG
 92
 93Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:
 94
 95 (define three 3)
 96 (display #<#EOF
 97 This is a simple string with an embedded `##' character
 98 and substituted expressions: (+ three 99) ==> #(+ three 99)
 99 (three is "#{three}")
100 EOF
101 )
102
103prints
104
105 This is a simple string with an embedded `#' character
106 and substituted expressions: (+ three 99) ==> 102
107 (three is "3")
108
109=== Foreign Declare
110
111<read>#></read>
112
113 #> ... <#
114
115Abbreviation for {{(foreign-declare " ... ")}}.
116
117=== String escape sequences
118
119String-literals may contain the following escape sequences:
120
121<table style="margin-top: 1em; max-width: 40em">
122<tr><th>Escape sequence</th><th>Character</th></tr>
123<tr><td>{{\n}}</td><td>line feed / newline</td></tr>
124<tr><td>{{\t}}</td><td>tab</td></tr>
125<tr><td>{{\r}}</td><td>carriage return</td></tr>
126<tr><td>{{\b}}</td><td>backspace</td></tr>
127<tr><td>{{\a}}</td><td>bell</td></tr>
128<tr><td>{{\v}}</td><td>vertical tab</td></tr>
129<tr><td>{{\f}}</td><td>form feed</td></tr>
130<tr><td>{{\x}}''XX;''</td><td>hexadecimal 8-bit character code</td></tr>
131<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>
132<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>
133<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>
134<tr><td>{{\|}}   {{\"}}    {{\\}}    {{\'}}</td><td>the escaped character</td></tr>
135</table>
136
137
138=== Bang
139
140<read>#!</read>
141
142 #!...
143
144Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.
145
146; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored
147
148; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned
149
150; DSSSL Formal Parameter List Annotation : If followed by any of the character sequences {{optional}}, {{rest}} or {{key}}, then a symbol with the same name (and prefixed with {{#!}}) is returned
151
152; Read Mark Invocation : If a ''read mark'' with the same name as the token is registered, then its procedure is called and the result of the read-mark procedure will be returned
153
154=== Conditional Expansion
155
156<read>#+</read>
157
158 #+FEATURE EXPR
159
160Rewrites to
161
162 (cond-expand (FEATURE EXPR) (else))
163
164and performs the feature test at macroexpansion time.  Therefore, it may not
165work as expected when used within a macro form.
166
167---
168Previous: [[Deviations from the standard]]
169
170Next: [[Interface to external functions and variables]]
Trap